const db = require("../db/mysql")

exports.articlePublish = (req, res) => {
    if (!req.file) {
        return res.cc("文章封面不能为空")
    }

    let articleObj = {
        ...req.body,
        cover_img: req.file.filename,
        pub_date: new Date(),
        author_id: req.auth.id,
    }

    //定义sql
    let sql = "INSERT INTO ev_articles SET ?"
    db.query(sql, articleObj, (err, results) => {
        if (err) {
            return res.cc(err)
        }
        if (results.affectedRows !== 1) {
            return res.cc("文章发布失败")
        }
        res.cc("文章发布成功", 0)
    })
}
